//
//  DMComplianceDelegate.h
//  DualMediationSDK
//
//  合规委托协议定义
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@class DMComplianceManager;
@class DMComplianceResult;

// 前向声明
@class DMUserConsent;
@class DMAdRequest;

/**
 * ATT状态枚举
 */
typedef NS_ENUM(NSInteger, DMATTStatus) {
    DMATTStatusNotRequired = 0,     // iOS 14以下不需要
    DMATTStatusNotDetermined = 1,   // 未确定
    DMATTStatusAuthorized = 2,      // 已授权
    DMATTStatusDenied = 3,          // 已拒绝
    DMATTStatusRestricted = 4,      // 受限制
    DMATTStatusNotSupported = 5     // 不支持
};

/**
 * 合规检查完成回调
 */
typedef void(^DMComplianceCheckCompletion)(BOOL success, NSError * _Nullable error);

/**
 * 合规状态类
 */
@interface DMComplianceStatus : NSObject
@property (nonatomic, assign) DMATTStatus attStatus;
@property (nonatomic, assign) BOOL gdprApplies;
@property (nonatomic, assign) BOOL gdprConsent;
@property (nonatomic, assign) BOOL ccpaApplies;
@property (nonatomic, assign) BOOL ccpaOptOut;
@property (nonatomic, strong) NSString *region;
@end

/**
 * 合规检查结果类
 */
@interface DMComplianceResult : NSObject
@property (nonatomic, assign) BOOL isCompliant;
@property (nonatomic, strong) DMComplianceStatus *complianceStatus;
@property (nonatomic, strong, nullable) DMUserConsent *userConsent;
@property (nonatomic, strong, nullable) NSError *error;
@end

/**
 * DMAdRequest 在 DMAdConfig.h 中定义
 */

/**
 * 合规委托协议
 */
@protocol DMComplianceDelegate <NSObject>

@optional

#pragma mark - ATT相关回调

/**
 * ATT权限请求即将显示
 * @param complianceManager 合规管理器
 */
- (void)dmComplianceManagerWillRequestATTPermission:(DMComplianceManager *)complianceManager;

/**
 * ATT权限请求完成
 * @param complianceManager 合规管理器
 * @param status ATT状态
 */
- (void)dmComplianceManager:(DMComplianceManager *)complianceManager didUpdateATTStatus:(NSInteger)status;

#pragma mark - GDPR相关回调

/**
 * GDPR同意弹窗即将显示
 * @param complianceManager 合规管理器
 */
- (void)dmComplianceManagerWillShowGDPRConsent:(DMComplianceManager *)complianceManager;

/**
 * GDPR同意状态更新
 * @param complianceManager 合规管理器
 * @param consented 是否同意
 * @param consentString 同意字符串
 */
- (void)dmComplianceManager:(DMComplianceManager *)complianceManager didUpdateGDPRConsent:(BOOL)consented consentString:(nullable NSString *)consentString;

#pragma mark - CCPA相关回调

/**
 * CCPA隐私弹窗即将显示
 * @param complianceManager 合规管理器
 */
- (void)dmComplianceManagerWillShowCCPAPrivacyForm:(DMComplianceManager *)complianceManager;

/**
 * CCPA选择状态更新
 * @param complianceManager 合规管理器
 * @param optOut 是否选择退出
 */
- (void)dmComplianceManager:(DMComplianceManager *)complianceManager didUpdateCCPAOptOut:(BOOL)optOut;

#pragma mark - 合规状态回调

/**
 * 合规检查开始
 * @param complianceManager 合规管理器
 */
- (void)dmComplianceManagerDidStartComplianceCheck:(DMComplianceManager *)complianceManager;

/**
 * 合规检查完成
 * @param complianceManager 合规管理器
 * @param result 检查结果
 */
- (void)dmComplianceManager:(DMComplianceManager *)complianceManager didCompleteComplianceCheck:(DMComplianceResult *)result;

/**
 * 合规检查失败
 * @param complianceManager 合规管理器
 * @param error 错误信息
 */
- (void)dmComplianceManager:(DMComplianceManager *)complianceManager didFailComplianceCheck:(NSError *)error;

#pragma mark - 用户同意UI回调

/**
 * 需要显示自定义同意UI
 * @param complianceManager 合规管理器
 * @param complianceType 合规类型 (ATT/GDPR/CCPA)
 * @param completion 完成回调
 */
- (void)dmComplianceManager:(DMComplianceManager *)complianceManager
         shouldShowConsentUI:(NSString *)complianceType
                  completion:(void(^)(BOOL userConsented))completion;

/**
 * 需要显示隐私政策
 * @param complianceManager 合规管理器
 * @param viewController 展示的视图控制器
 */
- (void)dmComplianceManager:(DMComplianceManager *)complianceManager shouldShowPrivacyPolicy:(id)viewController;

/**
 * 合规检查完成回调
 */
- (void)complianceCheckDidComplete:(BOOL)success error:(NSError * _Nullable)error;

/**
 * ATT权限请求完成回调
 */
- (void)attPermissionDidComplete:(DMATTStatus)status;

/**
 * GDPR同意请求完成回调
 */
- (void)gdprConsentDidComplete:(BOOL)granted consentString:(NSString * _Nullable)consentString;

/**
 * CCPA选择退出回调
 */
- (void)ccpaOptOutDidComplete:(BOOL)optedOut;

@end

NS_ASSUME_NONNULL_END